<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    var str = 'id=1&name=zhangsan&age=18&className=2003';
    
    var arr = str.split('&');

    var obj = {};
    for(var i=0;i<arr.length;i++){
        var newArr = arr[i].split('=');
        obj[newArr[0]] = newArr[1];
    }
    console.log(obj);
    
    var obj1 = {
        id:1,
        name:'zhangsan',
        age:18,
        className:2003
    }
    var str1 = '';
    for(var key in obj1){
        str1 += key + '=' + obj1[key] + '&';
    }
    console.log(str1.substr(0,str1.length - 1));
    
</script>
</html>